package view;

import java.util.ArrayList;
import java.util.Collection;

import javax.swing.table.AbstractTableModel;

import model.OfferedCourse;

public class TaskModel extends AbstractTableModel {
	/* Required for the serializable interface */
	private static final long serialVersionUID = 1L;
	/* List of column names */
	private static final String[] columnNames = { "Teacher", "Course", "Classroom", "Time","Status" };
	/* List of offered courses */
	ArrayList<OfferedCourse> offeredCourses;
	
	/** Constructs a new task model */
	public TaskModel(Collection<OfferedCourse> offeredCourses) {
		this.offeredCourses = (ArrayList<OfferedCourse>)offeredCourses;
	}
	
	/** Returns the row count of the list */
	@Override
	public int getRowCount() {
		return this.offeredCourses.size();
	}
	
	/** Returns the column count of the list */
	@Override
	public int getColumnCount() {
		return 5;
	}
	
	/** Returns the column name */
	@Override
	public String getColumnName(int column) {
		return columnNames[column];
	}
	
	/** Returns the appropriate value for given row and column */
	@Override
	public Object getValueAt(int row, int column) {
		OfferedCourse offeredCourse = this.offeredCourses.get(row);
		
		switch (column) {
			case 0:
				return offeredCourse.getTeacher();
			case 1:
				return offeredCourse.getCourse();
			case 2:
				return offeredCourse.getClassroom();
			case 3:
				return offeredCourse.getTimeBlock();
			case 4:
				return offeredCourse.getState();
			case 5:
				return offeredCourse.getId();
			default:
				return "";
		}
	}
}